package com.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
//开启Swagger2
@EnableSwagger2
public class SwaggerConfig {

    // 自定义分组
    @Bean
    public Docket docket1() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("分组1");
    }

    //配置Swagger的Docket的bean实例
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //是否启动Swagger
                .enable(true)
                .select()
                /*
                RequestHandlerSelectors 配置要扫描接口的方式

                basePackage : 指定要扫描的包
                any() : 扫描全部
                none() : 不扫描

                withClassAnnotation : 扫描类上的注解
                withMethodAnnotation : 扫描方法上的注解
                 */
                // .apis(RequestHandlerSelectors.basePackage("com.example.controller"))
                // 过滤请求
                // .paths(PathSelectors.ant("/example/**"))
                .build();
    }

    private ApiInfo apiInfo() {
        //作者信息
        Contact contact = new Contact("联系人名", "联系人链接", "联系人链接邮箱");
        return new ApiInfo(
                "API 文档标题",
                "描述",
                "v1.0",
                "组织链接",
                contact, // 联系人信息
                "Apach 2.0 许可",
                "http://www.apache.org/licenses/LICENSE-2.0"
        );
    }
}
